package com.ruoyi.web.sso.controller;


import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.sso.domain.Platform;
import com.ruoyi.web.sso.domain.vo.AddPlatform;
import com.ruoyi.web.sso.service.IPlatformService;
import io.swagger.annotations.*;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 系统表 前端控制器
 * </p>
 *
 * @author cdd
 * @since 2021-10-20
 */
@Controller
@RequestMapping("/sso/platform")
@Api(tags = "系统信息")
public class PlatformController extends BaseController {

    @Autowired
    private IPlatformService platformService;

    @RequestMapping(value="/list",method= RequestMethod.POST)
    @ApiOperation(value="查询系统列表",notes="查询系统列表")
    @ApiResponses({
            @ApiResponse(code = 200,message = "OK",response = Platform.class),
    })
    @ResponseBody
    public AjaxResult list()
    {
        return AjaxResult.success(platformService.selectPlatformList(new Platform()));
    }


    /**
     * 查询系统列表
     */
    @PostMapping("/platformList")
    @ResponseBody
    public TableDataInfo platformList(Platform platform)
    {
        startPage();
        List<Platform> list = platformService.selectPlatformList(platform);
        return getDataTable(list);
    }

    @PostMapping("/add")
    @ApiOperation(value="新增系统",notes="新增系统")
    @ResponseBody
    public AjaxResult add(@Validated AddPlatform addPlatform)
    {
        return platformService.add(addPlatform);
    }

    @PostMapping("/remove")
    @ApiOperation(value="逻辑删除系统",notes="逻辑删除系统")
    @ResponseBody
    public AjaxResult remove(@ApiParam(value = "系统ID") @RequestParam String platformId)
    {
        return platformService.remove(platformId);
    }

    /**
     * 修改保存系统
     */
    @RequiresPermissions("sso:platform:edit")
    @Log(title = "系统", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Platform platform)
    {
        return toAjax(platformService.updatePlatform(platform));
    }

}
